2020-2021 Sunseeker Telemetry and Lighting System
sd24_ex4_singleConversionSingleChannelPolling.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // MSP430i20xx SD24 Example 04 - SD24, Single Conversion on a Single Channel, Poll IFG
34 //
35 // Description: This program uses the SD24 module to perform a single
36 // conversion on a single channel. The SD24 interrupt flag for CH0 is polled
37 // to determine when a conversion has completed.
38 //
39 // Test by applying a voltage to the input channel and setting a breakpoint
40 // at the indicated line. Run program until it reaches the breakpoint, then use
41 // the debugger's watch window to view the conversion results.
42 //
43 // Results (upper 16 bits only) are stored in the variable "results"
44 //
45 // ACLK = 32kHz, MCLK = SMCLK = Calibrated DCO = 16.384MHz, SD_CLK = 1.024MHz
46 // * Ensure low_level_init.c is included when building/running this example *
47 //
48 // Notes: For minimum Vcc required for SD24 module - see datasheet
49 // 100nF cap btw Vref and AVss is recommended when using 1.2V ref
50 //
51 // MSP430i20xx
52 // -----------------
53 // /|\| |
54 // | | |
55 // --|RST |
56 // | |
57 // Vin1+ -->|A0.0+ VREF |---+
58 // Vin1- -->|A0.0- | |
59 // | | -+- 100nF
60 // | | -+-
61 // | | |
62 // | AVss |---+
63 //
64 // T. Witt
65 // Yang Lu
66 // Texas Instruments, Inc
67 // June 2014
68 // Built with Code Composer Studio v5.5
69 //******************************************************************************
70 #include "driverlib.h"
71 
72 uint16_t results; // SD24 Conversion Results
73 
74 void main(void) {
75  // Stop WDT
76  WDT_hold(WDT_BASE);
77 
78  // Internal ref
79  SD24_init(SD24_BASE, SD24_REF_INTERNAL);
80 
81  //Ch0 single mode
82  SD24_initConverterAdvancedParam param = {0};
83  param.converter = SD24_CONVERTER_0;
84  param.conversionMode = SD24_SINGLE_MODE;
85  param.groupEnable = SD24_NOT_GROUPED;
86  param.inputChannel = SD24_INPUT_CH_ANALOG;
87  param.dataFormat = SD24_DATA_FORMAT_2COMPLEMENT;
88  param.interruptDelay = SD24_FOURTH_SAMPLE_INTERRUPT;
89  param.oversampleRatio = SD24_OVERSAMPLE_256;
90  param.gain = SD24_GAIN_1;
91  SD24_initConverterAdvanced(SD24_BASE, &param);
92 
93  // Delay ~200us for 1.2V ref to settle
94  __delay_cycles(3200);
95 
96  while(1) {
97  // Start conversion
98  SD24_startConverterConversion(SD24_BASE, SD24_CONVERTER_0);
99  // Poll IFG until conversion completes
100  while(!SD24_getInterruptStatus(SD24_BASE, SD24_CONVERTER_0, SD24_CONVERTER_INTERRUPT));
101  // Save SD24 conversion results
102  results = SD24_getHighWordResults(SD24_BASE, SD24_CONVERTER_0);
103  __no_operation(); // SET BREAKPOINT HERE
104  }
105 }
MPU_initThreeSegmentsParam param
__no_operation()
__delay_cycles(500000)